#! /usr/bin/env python3

class Solution:
    def isValid(self, s):
       # 定义字典
        d = {')': '(', ']': '[', '}': '{'}
        # 定义一个栈
        stack = []
        # 判断字符个数，奇数个则不能成对，直接结束
        if s.__len__() % 2:
            return False
        for i in s:
            if i in '([{':
                stack.append(i)
                print('添加后的栈', stack)
            else:
                item = stack.pop()
                print('弹出后的栈', stack)
                if item != d[i]:
                    return False
        if not stack:
            return True
        else:
            return False

obj = Solution()
print(obj.isValid('()'))
